package io.geekidea.springbootplus.system.service.impl;


import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.system.entity.SysCartItem;
import io.geekidea.springbootplus.system.entity.SysDepartment;
import io.geekidea.springbootplus.system.mapper.SysCartItemMapper;
import io.geekidea.springbootplus.system.mapper.SysDepartmentMapper;
import io.geekidea.springbootplus.system.service.SysCartItemService;
import io.geekidea.springbootplus.system.service.SysDepartmentService;
import io.geekidea.springbootplus.system.vo.SysCartItemQueryVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
public class SysCartItemServiceImpl extends BaseServiceImpl<SysCartItemMapper, SysCartItem> implements SysCartItemService {

    @Resource
    private SysCartItemMapper cartItemMapper;

    @Override
    public boolean addToCart(SysCartItem cartItem) throws Exception {
        System.out.println(cartItem);
        return cartItemMapper.insertCartItem(cartItem) > 0;
    }

    @Override
    public boolean deleteFromCart(int id) throws Exception {
        return cartItemMapper.deleteCartItem(id) > 0;
    }

    @Override
    public boolean deleteAllFromCart(List<Integer> ids) throws Exception {
        return cartItemMapper.deleteAllCartItem(ids) > 0;
    }

    @Override
    public List<SysCartItemQueryVo> findCartItemsByUserId(Integer userId) throws Exception {
        return cartItemMapper.selectCartItemsByUserId(userId);
    }

    @Override
    public boolean updateCartItemByProductId(Integer id) throws Exception {
        return cartItemMapper.updateCartItem(id)>0;
    }


}
